package com.zhaozhaonews.article.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhaozhaonews.model.article.entity.ApArticleConfig;
import com.zhaozhaonews.article.mapper.ApArticleConfigMapper;
import com.zhaozhaonews.article.service.ApArticleConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <p>
 * APP已发布文章配置表 服务实现类
 * </p>
 *
 * @author WanJL
 * @since 2025-02-17
 */
@Service
@Slf4j
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {

    /**
     * 根据map里的键值对修改article_config表
     *
     * @param map
     */
    @Override
    public void updateByMap(Map map) {
        // 0 下架，1 上架
        Object enable = map.get("enable");
        boolean isDown = true;
        if (enable.equals(1)) {
            isDown = false;
        }
        //修改新闻配置
        lambdaUpdate()
                .eq(ApArticleConfig::getArticleId, map.get("articleId"))
                .set(ApArticleConfig::getIsDown, isDown)
                .update();
    }
}
